Ext.namespace('Ext.ux');
Ext.ux.OnDemandLoad = function(){
    loadComponent = function(component,callback){
        var fileType = component.substring(component.lastIndexOf('.'));
        var head = document.getElementsByTagName("head")[0];
        var done = false;
        if (fileType === ".js") {
			var data = new Date();
			var ms   = data.getMilliseconds();
			var sec  = data.getSeconds();
			var hora = data.getHours();
			var dia = data.getDate();
			var nocache = "";
			//var nocache = "?nocache=" + dia + hora + sec + ms;
            var fileRef = document.createElement('script');
            fileRef.setAttribute("type", "text/javascript");
            fileRef.setAttribute("src", component + nocache);
            fileRef.onload = fileRef.onreadystatechange = function(){
                    if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete") ) {
                        done = true;
						if ( callback != "" ){
							eval(callback+'()');
						}
                        head.removeChild(fileRef);
                    }
                };
        } else if (fileType === ".css") {
            var fileRef = document.createElement("link");
            fileRef.setAttribute("type", "text/css");
            fileRef.setAttribute("rel", "stylesheet");
            fileRef.setAttribute("href", component);
        }
        if (typeof fileRef != "undefined") {
            head.appendChild(fileRef);
        }
    };

    return {
        load: function(components, callback){
            Ext.each(components, function(component){
                loadComponent(component,callback);
            });
        }
    };
}();